﻿///<copyright>
/// Copyright © 2009 Stephen Styrchak. All Rights Reserved.
///</copyright>
using System;
using System.ComponentModel;

namespace Ferpect.ComponentModel.Design
{
    public class DynamicReadOnlyPropertyDescriptor : PropertyDescriptorWrapper
    {
        public delegate bool GetReadOnly();
        private GetReadOnly getReadOnlyValue;

        public DynamicReadOnlyPropertyDescriptor(PropertyDescriptor innerPropertyDescriptor, GetReadOnly getReadOnlyValue)
            : this(innerPropertyDescriptor, new Attribute[0], getReadOnlyValue)
        {
        }

        public DynamicReadOnlyPropertyDescriptor(PropertyDescriptor innerPropertyDescriptor, Attribute[] attributes, GetReadOnly getReadOnlyValue)
            : base(innerPropertyDescriptor, attributes)
        {
            if (getReadOnlyValue == null) throw new ArgumentNullException("getReadOnlyValue");
            this.getReadOnlyValue = getReadOnlyValue;
        }

        public override bool IsReadOnly
        {
            get
            {
                return this.getReadOnlyValue();
            }
        }
    }
}
